<?php
/*
 * @Description  : 类别管理
 * @Author       : https://github.com/skyselang
 * @Date         : 2020-03-30
 * @LastEditTime : 2020-12-25
 */

namespace app\admin\controller;

use app\admin\service\CateGoryService;
use app\admin\validate\CateGoryValidate;
use think\facade\Request;

class CateGory
{
    /**
     * 类别列表
     *
     * @method GET
     * 
     * @return json
     */
    public function cateGoryList()
    {
        $page  = Request::post('page/d', 1);
        $limit = Request::post('limit/d', 10);
        $getAll = Request::post('get_all/b', false);
        $field = Request::post('field/s', "*"); //寻找字段
        $param = array( 
            'category_type'   => Request::post("category_type/d",''),
            'category_name'   => Request::post("category_name/s",''),
            'category_status' => Request::post("category_status/d",'')
        );
        $data = CateGoryService::findList($param, $page, $limit, $field,$getAll);
        return success($data);
    }


    /**
     * 类别添加
     *
     * @method POST
     * 
     * @return json
     */
    public function cateGoryAdd()
    {
       
        $param = array(
            'category_type' => Request::post("category_type/d",''),
            'category_name' => Request::post("category_name/s",''),
            'category_sort' => Request::post("category_sort/d",1),
            'category_remark' => Request::post("category_remark/s",'')
        );
        validate(CateGoryValidate::class)->scene('cateGory_add')->check($param);

        $data = CateGoryService::add($param);

        return success($data);
    }

    /**
     * 类别修改
     *
     * @method POST
     * 
     * @return json
     */
    public function cateGoryEdit()
    {
        $param = array(
            'category_id'     => Request::post("category_id/d",''),
            'category_type'   => Request::post("category_type/d",''),
            'category_name'   => Request::post("category_name/s",''),
            'category_sort'   => Request::post("category_sort/d",1),
            'category_remark' => Request::post("category_remark/s",'')
        );
        validate(CateGoryValidate::class)->scene('cateGory_edit')->check($param);
        $data = CateGoryService::edit($param);
        return success($data);
    }

    /**
     * 类别删除
     *
     * @method POST
     * 
     * @return json
     */
    public function cateGoryDel()
    {
        $param['category_id'] = Request::post('category_id/d', '');
        $param['category_type'] = Request::post('category_type/d', '');
        validate(CateGoryValidate::class)->scene('cateGory_dele')->check($param);
        $data = CateGoryService::dele($param);
        return success($data);
    }

    /**
     * 类别状态改变
     *
     * @method POST
     * 
     * @return json
     */
    public function cateGoryStatusUpdate()
    {
        $param['category_id'] = Request::post('category_id/d', '');
        $param['category_status'] = Request::post('category_status/d', '');
        $param['category_type'] = Request::post('category_type/d', '');
        validate(CateGoryValidate::class)->scene('cateGory_status_update')->check($param);
        $data = CateGoryService::cateGoryStatusUpdate($param);
        return success($data);
    }
}
